# -*- coding: utf-8 -*-

from email.mime.text import  MIMEText
from email.header import Header
import smtplib
import getpass

def send_mail(body,sender,receivers,subject,server,passwd):

    #准备邮件
    #plain:纯文本,相对与富文本
    msg = MIMEText(body,'plain','utf8')
    msg['From'] = Header(sender,'utf8')    #发件人
    msg['To'] = Header(receivers[1],'utf8')   #收件人
    msg['Subject'] = Header(subject,'utf8')

    #发送邮件
    smtp = smtplib.SMTP()
    smtp.connect(server)
    #smtp.starttls()    #如果服务器要求安全链接,则打开此注释
    smtp.login(sender,passwd)
    smtp.sendmail(sender,receivers,msg.as_bytes())

if __name__ == '__main__':
    body = 'nihao1 发送邮件\n'
    sender = '1871356147@qq.com'
    receives = ['1871356147@qq.com','19804710497@163.com']
    subject = 'xuehaoning'
    server = 'smtp.163.com'
    passwd = getpass.getpass()
    send_mail(body,sender,receives,subject,server,passwd)